package org.getOffer.offer06;

/**
 * @Author: wjy
 * @Date: 2021/9/22 13:23
 */
public class Solution {

    public static void main(String[] args) {
        Node node3 = new Node(2, null);
        Node node2 = new Node(3, node3);
        Node node1 = new Node(1, node2);
        Node node = new Node(0, node1);
        reverse(node);

    }

    public static void reverse(Node root) {
        if (root == null || root.next == null) {
            System.out.println("错！");
        }

        Node temp = root.next;
        Node nodeNext = null;
        Node resNode = null;
        int count = 0;

        while (temp != null) {
            nodeNext = temp.next;
            temp.next = resNode;
            resNode = temp;
            temp = nodeNext;
            count++;
        }

        Node node = resNode;
        int[] num = new int[count];

        int i=0;
        while (true) {

            if (node == null) {
                break;
            }

            num[i++] = node.val;

            node = node.next;

        }

        System.out.println(num.length);

    }

}

class Node {

    int val;
    Node next;

    public Node(int val, Node next) {
        this.val = val;
        this.next = next;
    }
}
